dofile (getScriptPath() .. "\\..\\processor\\processor.lua")
dofile (getScriptPath() .. "\\..\\processor\\log.lua")

dofile (getScriptPath() .. "\\..\\lib\\lib.lua")
dofile (getScriptPath() .. "\\..\\lib\\orders.lua")
dofile (getScriptPath() .. "\\..\\lib\\actions.lua")

script_name = string.gsub(string.gsub(debug.getinfo(1).short_src, "%.[^%.]*$", ""), "^.*[\\/]", "")

assets_delay = 0
run_delay = processor:GetTime(lib.global.file_ttl * 1000)		-- transfer files should be overdue

processor:AddHandler("OnRun", function(t)
	assets_delay = false
end)

processor:AddInit(function()
	if not lib:isConnected() then return true end
	client_code = lib:GetUser()
	if not client_code then return true end
	
	if not assets_delay then assets_delay = processor:GetTime(5000) end
	if not processor:IsDelay(assets_delay) then return true end
	
	if not processor:IsDelay(run_delay) then return true end
	--message("Client Code " .. client_code)
	
	script_id = client_code .. "#" .. script_name
	log_file = lib.path.log .. script_id .. ".log"
end)
	
processor:AddInit(function()
	processor:InitLog(log_file)
end)

processor:AddInit(function()
	orders:AddOnLimitStopHandler()
end)

processor:AddInit(function()
	message("Assets " .. tostring(lib:GetAssets()) .. " Money " .. tostring(lib:GetMoney()))
	processor:log("started")
end)
	
processor:AddTimer(function()
	return actions:LoadAction()
end)
	
processor:AddTimer(function()
	return orders:LoadLimit()
end)
	
processor:AddTimer(function()
	return orders:LoadStop()
end)
	
processor:AddTimer(function()
	return orders:LoadTake()
end)
